<?php /* Smarty version 2.6.20, created on 2016-07-19 18:20:12
         compiled from coupons.htm */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'date_format', 'coupons.htm', 100, false),array('modifier', 'default', 'coupons.htm', 112, false),array('function', 'html_select_time', 'coupons.htm', 101, false),)), $this); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>优惠券</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../script/jquery-1.4.4.min.js"></script>
<script language="javascript" src="../script/Calendar.js"></script>
<script type="text/javascript" src="../script/jquery.validation.min.js"></script>
<script>
$(function(){
	$('#form').validate({
		errorPlacement: function(error, element){
			element.next('.form-error').append(error);
		},      
		rules : {
			title:{
				required:true
			},
            cpns_then:{
                min:1
            }
		},
		messages : {
			title:{
				required:'请填写名称'
			},
            cpns_then:{
                min:'请确认金额'
            }
		}
	});
});
</script>
</head>
<body>
	<div class="container">
        <div class="flow">
            <div class="itemtitle">
                <h3>优惠券</h3>
                <ul>
                    <li <?php if ($_GET['operation'] == ''): ?>class="current"<?php endif; ?>><a href="?m=activity&s=coupons.php"><span>管理</span></a></li>
                    <li <?php if ($_GET['operation'] == 'add'): ?>class="current"<?php endif; ?>><a href="?m=activity&s=coupons.php&operation=add"><span>添加</span></a></li>
                    <?php if ($_GET['operation'] == 'edit'): ?>
                    <li class="current"><a href="#"><span>修改</span></a></li>
                    <?php endif; ?>
                    <li <?php if ($_GET['operation'] == 'users'): ?>class="current"<?php endif; ?>><a href="?m=activity&s=coupons.php&operation=users"><span>优惠券列表</span></a></li>
                    
                </ul>
            </div>
        </div>
        <div class="h35"></div>  
        <?php if ($_GET['operation'] == 'add' || $_GET['operation'] == 'edit'): ?>
            <form name="form" id="form" method="post">
            <input name="id" type="hidden" id="id" value="<?php echo $this->_tpl_vars['de']['id']; ?>
">
            <table class="table">
                <thead>
                    <tr>
                        <th class="partition" colspan="99">优惠券</th>
                    </tr>
                </thead>
                <tbody>
                <tr>
                    <td width="100">名称</td>
                    <td>
                    <input name="title" id="title" type="text" class="w350" value="<?php echo $this->_tpl_vars['de']['title']; ?>
"><div id="form-error" class="form-error"></div>
                    </td>
                </tr>
                
                
                <tr>
                    <td>优惠券类型</td>
                    <td>
                    <input type="radio" name="type" value="0" id="type0" <?php if ($this->_tpl_vars['de']['type'] == 0): ?>checked="checked"<?php elseif ($_GET['operation'] == 'edit'): ?>disabled<?php endif; ?>/><label for="type0">通用码</label>
                    
                    <input type="radio" name="type" value="1" id="type1" <?php if ($this->_tpl_vars['de']['type'] == 1): ?>checked="checked"<?php elseif ($_GET['operation'] == 'edit'): ?>disabled<?php endif; ?>/><label for="type1">唯一编号</label>
                    
                    <input type="radio" name="type" value="2" id="type2" <?php if ($this->_tpl_vars['de']['type'] == 2): ?>checked="checked"<?php elseif ($_GET['operation'] == 'edit'): ?>disabled<?php endif; ?>/><label for="type2">积分兑换</label>
                    
                    <input type="radio" name="type" value="3" id="type3" <?php if ($this->_tpl_vars['de']['type'] == 3): ?>checked="checked"<?php elseif ($_GET['operation'] == 'edit'): ?>disabled<?php endif; ?>/><label for="type3">页面领取</label>
										
                    <input type="radio" name="type" value="4" id="type4" <?php if ($this->_tpl_vars['de']['type'] == 4): ?>checked="checked"<?php elseif ($_GET['operation'] == 'edit'): ?>disabled<?php endif; ?>/><label for="type4">事件触发</label>
										
					<input type="radio" name="type" value="5" id="type5" <?php if ($this->_tpl_vars['de']['type'] == 5): ?>checked="checked"<?php elseif ($_GET['operation'] == 'edit'): ?>disabled<?php endif; ?>/><label for="type5">会员分享</label>
                
                    </td>
                </tr>
                
                <tr>
                	<td colspan="2">
                		<table class="table" id="type_span">
                			<tr <?php if ($this->_tpl_vars['de']['type'] != 1 && $this->_tpl_vars['de']['type'] != 0 && $this->_tpl_vars['de']['type'] != 3): ?>style="display:none;"<?php endif; ?> attr_type="0,1,3">
                				  <td width="120">起止时间</td>
                    <td>
                    <script language="javascript">
                    var cdr = new Calendar("cdr");
                    document.write(cdr);
                    cdr.showMoreDay = true;
                    </script>
                    <input onFocus="cdr.show(this);" class="ltext" type="text" name="stime" id="stime" value="<?php echo ((is_array($_tmp=$this->_tpl_vars['de']['start_time'])) ? $this->_run_mod_handler('date_format', true, $_tmp) : smarty_modifier_date_format($_tmp)); ?>
"> 
                    <?php echo smarty_function_html_select_time(array('use_24_hours' => true,'display_seconds' => false,'prefix' => 'start','time' => $this->_tpl_vars['de']['start_time']), $this);?>

                    - 
                    <input onFocus="cdr.show(this);" class="rtext" type="text" name="etime" id="etime" value="<?php echo ((is_array($_tmp=$this->_tpl_vars['de']['end_time'])) ? $this->_run_mod_handler('date_format', true, $_tmp) : smarty_modifier_date_format($_tmp)); ?>
">
                    <?php echo smarty_function_html_select_time(array('use_24_hours' => true,'display_seconds' => false,'prefix' => 'end','time' => $this->_tpl_vars['de']['end_time']), $this);?>

                    <div id="form-error" class="form-error"></div>
                    </td>	
                			</tr>
											<tr <?php if ($this->_tpl_vars['de']['type'] != 0): ?>style="display:none;"<?php endif; ?> attr_type="0">
												<td width="120">
													同一会员使用次数
												</td>
												   <td><input type="text" class="w60" name="per_type_0"  value="<?php echo ((is_array($_tmp=@$this->_tpl_vars['de']['per_type'])) ? $this->_run_mod_handler('default', true, $_tmp, 1) : smarty_modifier_default($_tmp, 1)); ?>
"/> <a href="#" title="如果不限制请填写0"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
													 </td>           		

												
												
											</tr>
                                                <tr <?php if ($this->_tpl_vars['de']['type'] != 3): ?>style="display:none;"<?php endif; ?> attr_type="3">
                                                <td width="120">
                                                    同一会员领取次数
                                                </td>
                                                   <td><input type="text" class="w60" name="per_type_3"  value="<?php echo ((is_array($_tmp=@$this->_tpl_vars['de']['per_type'])) ? $this->_run_mod_handler('default', true, $_tmp, 1) : smarty_modifier_default($_tmp, 1)); ?>
"/> <a href="#" title="如果不限制请填写0"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                                                     </td>                  

                                                
                                                
                                            </tr>


                                                <tr <?php if ($this->_tpl_vars['de']['type'] != 4): ?>style="display:none;"<?php endif; ?> attr_type="4">
                                                <td width="120">
                                                    同一会员触发次数
                                                </td>
                                                   <td><input type="text" class="w60" name="per_type_4"  value="<?php echo ((is_array($_tmp=@$this->_tpl_vars['de']['per_type'])) ? $this->_run_mod_handler('default', true, $_tmp, 1) : smarty_modifier_default($_tmp, 1)); ?>
"/> <a href="#" title="如果不限制请填写0"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                                                     </td>                  

                                                
                                                
                                            </tr>

                                            <tr <?php if ($this->_tpl_vars['de']['type'] != 5): ?>style="display:none;"<?php endif; ?> attr_type="5">
                                                <td width="120">
                                                    同一会员可领取单个分享次数
                                                </td>
                                                   <td><input type="text" class="w60" name="per_type_5"  value="<?php echo ((is_array($_tmp=@$this->_tpl_vars['de']['per_type'])) ? $this->_run_mod_handler('default', true, $_tmp, 1) : smarty_modifier_default($_tmp, 1)); ?>
"/> <a href="#" title="如果不限制请填写0"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                                                     </td>                  

                                                
                                                
                                            </tr>

											<tr <?php if ($this->_tpl_vars['de']['type'] != 2): ?>style="display:none;"<?php endif; ?> attr_type="2">
                <td width="120">
               			 兑换所需积分
                
                </td>
                <td>
               <input type="text" class="w60" name="cost_points"  value="<?php echo $this->_tpl_vars['de']['cost_points']; ?>
"/>
                
                </td>
                
                
                </tr>
								
								<tr <?php if ($this->_tpl_vars['de']['type'] == 0 || $this->_tpl_vars['de']['type'] == 1 || $this->_tpl_vars['de']['type'] == 3): ?>style="display:none;"<?php endif; ?> attr_type="2,4,5">
                <td width="120">
               			 领取/兑换券有效期
                
                </td>
                <td>
               第 <input type="text" class="w60" name="sday"  value="<?php if ($this->_tpl_vars['de']['id']): ?><?php echo $this->_tpl_vars['de']['start_time']; ?>
<?php else: ?>0<?php endif; ?>"/> 天开始,有效期  <input type="text" class="w60" name="eday"  value="<?php if ($this->_tpl_vars['de']['id']): ?><?php echo $this->_tpl_vars['de']['end_time']; ?>
<?php else: ?>7<?php endif; ?>"/> 天<a href="#" title="立即生效从第0天开始,有效期是从开始日起计算"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                
                </td>
                
                
                </tr>
								<tr <?php if ($this->_tpl_vars['de']['type'] == 0 || $this->_tpl_vars['de']['type'] == 1 || $this->_tpl_vars['de']['type'] == 2): ?>style="display:none;"<?php endif; ?> attr_type="3,4,5">
                <td width="120">
               			 使用场景
                
                </td>
                <td>
                <input type="text" class="w200" name="cpns_event_key"  value="<?php echo $this->_tpl_vars['de']['cpns_event_key']; ?>
"/>   <a href="#" title="请填写使用场景的key，如注册填写register，其他场景联系技术"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                </td>
                
                
                </tr>
											
								<tr <?php if (1): ?>style="display:none;"<?php endif; ?>>
                <td width="120">
               			 分享个数
                
                </td>
                <td>
              <input type="text" class="w60" name="cpns_rand_from"  value="10"/> 至  <input type="text" class="w60" name="cpns_rand_to"  value="20"/> 个随机<a href="#" title="分享个数会在此范围内随机"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                
                </td>
                
                
                </tr>
											
                		</table>
										
										
                	</td>
                	
                   
                </tr>
                <tr>
                    <td>促销类型</td>
                    <td>
                       		满：  <input type="text" class="w60" name="cpns_if" id="cpns_if" value="<?php echo $this->_tpl_vars['de']['cpns_if']; ?>
"/> 减： <input type="text" class="w60" name="cpns_then" id="cpns_then" value="<?php echo $this->_tpl_vars['de']['cpns_then']; ?>
"/><div id="form-error" class="form-error" style="display:inline-block;"></div>
                            <a href="#" title="不限制满足金额填0"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
                   
                    </td>
                </tr>
                
                
                
                   
                <tr>
                    <td>关联分类</td>
                    <td>
                <select class="ws350" name='catid' >
                    	<option value='0'>全部分类</option>
                        <!-- <?php $_from = $this->_tpl_vars['de']['cat']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['list']):
?>
             			<option <?php if ($this->_tpl_vars['de']['catid'] == $this->_tpl_vars['list']['catid']): ?> selected="selected" <?php endif; ?> value="<?php echo $this->_tpl_vars['list']['catid']; ?>
"><?php echo $this->_tpl_vars['list']['cat']; ?>
</option>
             			<?php $_from = $this->_tpl_vars['list']['scat']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['slist']):
?>
                            <option <?php if ($this->_tpl_vars['de']['catid'] == $this->_tpl_vars['slist']['catid']): ?> selected="selected" <?php endif; ?> value="<?php echo $this->_tpl_vars['slist']['catid']; ?>
">|__<?php echo $this->_tpl_vars['slist']['cat']; ?>
</option>
                            	    
                                    <?php $_from = $this->_tpl_vars['slist']['scat']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['lists']):
?>
                                    <option <?php if ($this->_tpl_vars['de']['catid'] == $this->_tpl_vars['lists']['catid']): ?> selected="selected" <?php endif; ?> value="<?php echo $this->_tpl_vars['lists']['catid']; ?>
">|____<?php echo $this->_tpl_vars['lists']['cat']; ?>
</option>
                            		<?php endforeach; endif; unset($_from); ?> 
                                    
                            <?php endforeach; endif; unset($_from); ?> 
             			<?php endforeach; endif; unset($_from); ?> -->
            		</select> 
            		<a href="#" title="关联分类后只有购买此分类下商品满足条件才可以使用优惠券"><img border="0" src="../image/admin/Help Circle.jpg" style="vertical-align:middle;"></a>
            		   
                 </td>
                </tr>
                <tr>
                    <td>优惠券说明</td>
                    <td>
                        <textarea style="width:80%; height:100px" name="desc"><?php echo $this->_tpl_vars['de']['desc']; ?>
</textarea>
                    </td>
                </tr>
                <tr>
                    <td>不支持商品</td>
                    <td>
                     <input type="hidden" id="hidden_related" name=except value="<?php echo $this->_tpl_vars['de']['except']; ?>
" />
                    
                    <table width="100%" class="alc">
                <tr id="related_tr">
                    <th class="al">产品名称</th>
                    <th width="100" align="left">产品编号</th>
                    <th width="100" align="left">销售价</th>
                    <th width="100" align="left">市场价</th>
                    <th width="100" align="left">成本价</th>
                    <th width="100" align="left">库存</th>
                    <th width="100"></th>
                </tr>
                
                                <?php $_from = $this->_tpl_vars['de']['products']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['list']):
?>
                <tr>
                    <td class="al"><?php echo $this->_tpl_vars['list']['pname']; ?>
</td>
                    <td><?php echo $this->_tpl_vars['list']['code']; ?>
</td>
                    <td><?php echo $this->_tpl_vars['list']['price']; ?>
</td>
                    <td><?php echo $this->_tpl_vars['list']['market_price']; ?>
</td>
                    <td><?php echo $this->_tpl_vars['list']['cost_price']; ?>
</td>
                    <td stock="<?php echo $this->_tpl_vars['list']['amount']; ?>
"></td>
                    <td><div><a href="javascript:;" class="deleterow" onClick="deleterow(this,<?php echo $this->_tpl_vars['list']['id']; ?>
,'related')">删除</a></div></td>
                </tr>
               <?php endforeach; endif; unset($_from); ?>
                <tr>
                    <td colspan="99" class="al">
                    <a class="addtr" id="related_button" nc_type="related" href="javascript:void(0);">添加产品</a>
                    </td>
                </tr>
            </table>
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                    <input type="radio" name="status" value="1" id="open" <?php if ($this->_tpl_vars['de']['status'] == 1): ?>checked="checked"<?php endif; ?>/><label for="open">开启</label>
                    <input type="radio" name="status" value="0" id="close" <?php if ($this->_tpl_vars['de']['status'] == 0): ?>checked="checked"<?php endif; ?>/><label for="close">关闭</label>
                    </td>
                </tr>
                
                <tr>
                    <td>&nbsp;</td>
                    <td>
                    <input class="submit" type="submit" value="提交">
                    <input name="act" type="hidden" id="action" value="<?php if (! $_GET['editid']): ?>save<?php else: ?>edit<?php endif; ?>">
                    </td>
                </tr>
                </tbody>
            </table>
            </form>
<script>
            $.each($('[stock]'),function(){
            	//alert($(this).attr('stock'));
            	var $stock=$(this);
            	
            	$.get('<?php echo $this->_tpl_vars['config']['weburl']; ?>
/admin/module.php?m=product&s=inventory_api.php&stock='+$(this).attr('stock'),function(data){
            		$stock.html(data);
            	});

            	
            });
            
            
            $(':input[name=type]').click(function(){
							var $$= $('#type_span').find('tr[attr_type]');
							var type_val=$(this).val();
							
							$$.each(function(){
								var attr_types= $(this).attr('attr_type').split(',');
								if($.inArray(type_val,attr_types)!='-1'){
									$(this).show();
								}else{
									$(this).hide();
								}
							})
            	
            })
            
            $('#related_button').bind('click',function(){
            	alert('暂缓开通');
            	
            	//window.parent.iframe_form("related","选择不能使用优惠券的商品",'<?php echo $this->_tpl_vars['config']['weburl']; ?>
/admin/module.php?m=product&s=product_list.php&type=related', 800, 505);
            	return false;
            	});

            var rowtypedata = [
                              	[
                              		[1, '', 'al'], 
                              		[1, ''], 
                              		[1, ''], 
                              		[1, ''], 
                              		[1, ''],
                              		[1, ''],
                              		[1, '<div><a href="javascript:;" class="deleterow" onClick="deleterow(this,{1})">删除</a></div>']
                              	
                              	]
                              ];
                              var addrowdirect = 0;
                              var addrowkey = 0;
            function addrow(name, type) {
            	
            	$('#'+name+'_tr').show();
            	var obj=$('#'+name+'_button')[0];	
            	var table = obj.parentNode.parentNode.parentNode.parentNode;
            	var iframe=window.parent.document.getElementById("iframe_"+name).contentWindow;
            	var tab=iframe.document.getElementById(name+"_table");
            	var checkbox= $(tab).find("input[class='checkitem']:checked");
            	var typedata = rowtypedata[type];
            	$.each(checkbox,function(i){
            		var value1=$("#hidden_"+name).val();
            		var value2=this.value
            		if(value1.indexOf(','+value2+',') <= 0 )
            		{
            			$("#hidden_"+name).val(value1+value2+',');	
            			var tr=$(this).parent().parent();
            			if(!addrowdirect) {
            				var row = table.insertRow(obj.parentNode.parentNode.rowIndex);
            			} else {
            				var row = table.insertRow(obj.parentNode.parentNode.rowIndex + 1);
            			}
            			for(var i = 0; i <= typedata.length - 1; i++) {
            				if(i<=6)
            				{
            					var cell = row.insertCell(i);
            					if(i==6)
            					{
            						var tmp = typedata[i][1];
            					}
            					else
            					{
            						var tmp = tr.find('td')[i+1].innerHTML;
            					}
            					if(i==0){
            						cell.className = typedata[i][2];
            					}
            					tmp = tmp.replace(/\{(n)\}/g, function($1) {return addrowkey;});
            					tmp = tmp.replace(/\{(\d+)\}/g, function($1, $2) { return value2+',\''+name+'\''; });
            					cell.innerHTML = tmp;
            				}
            			}
            			addrowkey ++;
            			addrowdirect =0;
            		}
            	});
            }
            function deleterow(obj,id,name) {
            	var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
            	var tr = obj.parentNode.parentNode.parentNode;
            	var value=$("#hidden_"+name).val();

            	var pattern = ','+id+',';
            	str = value.replace(new RegExp(pattern), ",");
            	$("#hidden_"+name).val(str);
            	table.deleteRow(tr.rowIndex);
            }
            
            </script>
            
            
            <?php elseif ($_GET['operation'] == 'users'): ?>
            <script type="text/javascript">
        $(function(){
            /* 全选 */
             $('.checkall').click(function(){
                var _self = this;
                $('.checkitem').each(function(){
                    if (!this.disabled)
                    {
                        $(this).attr('checked', _self.checked);
                    }
                });
                $('.checkall').attr('checked', this.checked);
            });	
            
            $('#send_button').click(function(){
            	var _status=0;
            	
            	$('.checkitem:checked').each(function(){
                    _status+=$(this).attr('status')*1
                });

            	if(_status>0){
            		alert('已禁用或已发放的不能发放');
            		return false;
            	}
            	$('#operation_hidden').val('send');
            	return true;
            	
            	
            	
            })
            
             $('#forbid_button').click(function(){
            	var _status=0;
            	
            	$('.checkitem:checked').each(function(){
                    _status+=$(this).attr('status')*1
                });
            	$('#operation_hidden').val('forbid');
            	return true;
            	
            	
            	
            })
            
            
        })
             </script>
             <form method="post" target="export_iframe" id="export_form" action=""><input type="hidden" value="export" name="act"/></form>
    <iframe src="" style="display:none;" id="export_iframe" name="export_iframe"></iframe>
    <div style="float:right" id="els_export">
            <a href="javascript:;" onclick="$('#export_form').submit();">导出EXCEL</a></div>
             <form action="" method="post">
        <table class="table">
        	<thead>
                <tr>
                    <th class="partition" colspan="99">已生成优惠券<div style="display:inline-block;float:right">筛选：
                    <select name="cpns_id" onchange="location.href='?m=activity&s=coupons.php&operation=users&cpns_id='+$(this).val()">
                    <option value="">全部</option>
                    <?php $_from = $this->_tpl_vars['de']['cpns']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['list']):
?>
                      <option value="<?php echo $this->_tpl_vars['list']['id']; ?>
" <?php if ($this->_tpl_vars['list']['id'] == $_GET['cpns_id']): ?>selected<?php endif; ?>><?php echo $this->_tpl_vars['list']['title']; ?>
</option>
                    <?php endforeach; endif; unset($_from); ?>
                    </select> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php if ($_GET['cpns_id']): ?> <input type="button" value="批量绑定" onclick="bindall()"><?php endif; ?></div></th>
                </tr>
            </thead>
            <tbody>
                <tr class="header">
                    <th width="30"></th>
                    <th>名称</th>
                    <th width="150">使用规则</th>
                    <th width="170">起止时间</th>
                    <th width="170">优惠码</th>
                    <th width="100">分类</th>
                    <th width="60">会员</th>
                    <th width="60">订单</th>
                    <th width="60">状态</th>
                    <th width="60">禁用</th>
                </tr>
                <?php $_from = $this->_tpl_vars['de']['list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['list']):
?>
                <tr>
                    <td><input type="checkbox" value="<?php echo $this->_tpl_vars['list']['id']; ?>
" class="checkitem" name="chk[]" status="<?php echo $this->_tpl_vars['list']['status']; ?>
"></td>
                    <td><?php echo $this->_tpl_vars['list']['title']; ?>
</td>
                    <td>满<?php echo $this->_tpl_vars['list']['cpns_if']; ?>
减<?php echo $this->_tpl_vars['list']['cpns_then']; ?>
</td>
                    <td><?php echo ((is_array($_tmp=$this->_tpl_vars['list']['start_time'])) ? $this->_run_mod_handler('date_format', true, $_tmp, "%Y-%m-%d %H:%M") : smarty_modifier_date_format($_tmp, "%Y-%m-%d %H:%M")); ?>
 -<br/> <?php echo ((is_array($_tmp=$this->_tpl_vars['list']['end_time'])) ? $this->_run_mod_handler('date_format', true, $_tmp, "%Y-%m-%d %H:%M") : smarty_modifier_date_format($_tmp, "%Y-%m-%d %H:%M")); ?>
</td>
                    <td><?php echo $this->_tpl_vars['list']['cpns_key']; ?>
</td>
                    <td>&nbsp;<?php echo ((is_array($_tmp=@$this->_tpl_vars['list']['catid'])) ? $this->_run_mod_handler('default', true, $_tmp, '全分类') : smarty_modifier_default($_tmp, '全分类')); ?>
</td>
                    <td>&nbsp;<?php if ($this->_tpl_vars['list']['uid']): ?><?php echo $this->_tpl_vars['list']['uname']; ?>
<br/>(<?php echo $this->_tpl_vars['list']['uid']; ?>
)<?php elseif ($this->_tpl_vars['list']['status'] == 1): ?><a href="javascript:bindto('<?php echo $this->_tpl_vars['list']['cpns_key']; ?>
');">绑定给</a><?php endif; ?></td>
                    <td>&nbsp;<?php echo $this->_tpl_vars['list']['order_id']; ?>
</td>
                    <td><?php if ($this->_tpl_vars['list']['status'] == 0): ?>已生成<?php elseif ($this->_tpl_vars['list']['status'] == 1): ?>已发放<?php elseif ($this->_tpl_vars['list']['status'] == 2): ?>已绑定<?php elseif ($this->_tpl_vars['list']['status'] == 3): ?>已使用<?php elseif ($this->_tpl_vars['list']['status'] == -1): ?>已禁用<?php endif; ?></td>
                    <td>
                    
                    <?php if ($this->_tpl_vars['list']['status'] == 0): ?><a onclick="return confirm('确定发放吗');" href="?m=activity&s=coupons.php&operation=send&delid=<?php echo $this->_tpl_vars['list']['id']; ?>
&cpns_id=<?php echo $this->_tpl_vars['list']['cpns_id']; ?>
">发放</a><?php endif; ?>
                    
                    
                    <a onclick="return confirm('确定禁用吗');" href="?m=activity&s=coupons.php&operation=forbid&delid=<?php echo $this->_tpl_vars['list']['id']; ?>
&cpns_id=<?php echo $this->_tpl_vars['list']['cpns_id']; ?>
">禁用</a> 
                    </td>
                </tr>
                <?php endforeach; else: ?>
                <tr>
                    <td class="norecord" colspan="99"><i></i><span>暂无符合条件的数据记录</span></td>
                </tr>
                <?php endif; unset($_from); ?>
            </tbody>
            <tfoot>
                <tr>
                	<td colspan="99">
                        <input type="checkbox" class="checkall" id="del">
                        <input type="hidden" name="operation" value="" id="operation_hidden" />
                        <input type="submit" value="发放" id="send_button"/>
                        <input type="submit" value="禁用" id="forbid_button"/>
                        
                    	<div class="page"><?php echo $this->_tpl_vars['de']['page']; ?>
共有<?php echo $this->_tpl_vars['countpro']; ?>
个记录 每页显示<input type="text" style="width:30px;" id="page_size" value="<?php echo $_GET['page_size']; ?>
">条<input type="button" value="确定" onclick="location.href='?m=activity&s=coupons.php&operation=users&cpns_id=<?php echo $_GET['cpns_id']; ?>
&page_size='+$('#page_size').val()"></div>
                    </td>
                </tr>
            </tfoot>
        </table>
        </form>
             <script type="text/javascript">
             function bindto(cpns_key){
            	 
            	 var inputText=prompt('请输入绑定的会员的ID或用户名');
            	 if(inputText){
            		 $.post('?m=activity&s=coupons.php&operation=bind','cpns_key='+cpns_key+'&uname='+inputText,function(data){
            			 if(data==1){
            				 alert('绑定成功');
            				 location.reload();
            			 }else{
            				 alert('绑定失败，'+data);
            			 }
            	 });
             }
             }
						 
						 
						 function bindall(){
						 	 window.parent.html_form("bindall","批量绑定优惠券",'<textarea id="bindallContent" style="width:100%;height:200px;"></textarea><div style="line-height:32px;"><span style="color:red;">逗号分隔会员id,每次最多支持1000个id,自动排重</span><input type="button" id="bindallBtn" value="确定" style="float:right;margin-right:20px;display:inline-block;margin-top:5px;"/></div>', 500,1);
							 window.parent.$('#bindallBtn').click(function(){
							 	var m_ids= window.parent.$('#bindallContent').val();
								var cpns_id = <?php echo $_GET['cpns_id']; ?>
;
								if(!m_ids){alert('不能为空');return false;}
								if(!cpns_id){return false;}
								if(/^[\d,]+$/.test(m_ids)){
									
									 $.post('?m=activity&s=coupons.php&operation=bindall','cpns_id='+cpns_id+'&uids='+m_ids,function(data){
            			 if(data==1){
            				 alert('绑定成功');
										 window.parent.DialogManager.close('bindall');
            				 location.reload();
            			 }
									 else if(/^2/.test(data)){
									 	window.parent.alert('部分绑定成功,'+data.replace(/^2/,''));
										window.parent.DialogManager.close('bindall');
										location.reload();
									 }
									 else{
            				 alert('绑定失败，'+data);
            			 }
            	 		});
									
									
								}else{
									alert('格式不对');return false;
								}
							 })						 
							 
						 }
             
             </script>
             
             
             
             
             
             
            
        <?php else: ?>
		<script type="text/javascript">
        $(function(){
            /* 全选 */
             $('.checkall').click(function(){
                var _self = this;
                $('.checkitem').each(function(){
                    if (!this.disabled)
                    {
                        $(this).attr('checked', _self.checked);
                    }
                });
                $('.checkall').attr('checked', this.checked);
            });	
            
            /**生成优惠券**/
            $('input[nc_type]').click(function(){
            	
            	
            	
            	var $$=$(this);
            	
            	
            	
            	var _id=$$.attr('nc_type');
            	
				var status=$('#cpns_status_'+_id).size();
            	
            	if(status){
            		alert('优惠券已经关闭，无法操作，请先开启优惠券');
            		return false;
            	}

                var make_type= $(':input[name=make_type_'+_id+']:checked').val();
            	
            	var cpns_id=$('#cpns_id_'+_id).val();
            	
            	var cpns_nums=$('#cpns_nums_'+_id).val();
            	if(confirm('将生成'+cpns_nums+'张优惠券,确定？')){
            					$.post('?m=activity&s=coupons.php&operation=make','cpns_id='+cpns_id+'&cpns_nums='+cpns_nums+'&make_type='+make_type,function(data){
            			if(data==1){
            				alert('生成成功');
            				
            			}else{
            				alert('生成失败'+data);
            			}
            			location.reload();
            			
            		})
            	}
            	return false;
            	
            	
            });
            
            
            
        });
        </script>
        <form action="" method="post">
        <table class="table">
        	<thead>
                <tr>
                    <th class="partition" colspan="99">优惠券列表</th>
                </tr>
            </thead>
            <tbody>
                <tr class="header">
                    <th width="30"></th>
                    <th>ID</th>
                    <th>名称</th>
                    <th width="120">使用规则</th>
                    <th width="120">起止时间</th>
                    <th width="40">生成数</th>
                    <th width="40">发放数</th>
                    <th width="40">绑定数</th>
                    <th width="40">使用数</th>
                    <th width="80">分类</th>
                    <th width="60">类型</th>
                    <th width="60">状态</th>
                    <th width="120">生成</th>
                    <th width="60"></th>
                </tr>
                <?php $_from = $this->_tpl_vars['de']['list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['list']):
?>
                <tr>
                    <td><input type="checkbox" value="<?php echo $this->_tpl_vars['list']['id']; ?>
" class="checkitem" name="chk[]"></td>
                    <td><?php echo $this->_tpl_vars['list']['id']; ?>
</td>
                    <td><a href="?m=activity&s=coupons.php&operation=users&cpns_id=<?php echo $this->_tpl_vars['list']['id']; ?>
"><?php echo $this->_tpl_vars['list']['title']; ?>
</a></td>
                    <td>满<?php echo $this->_tpl_vars['list']['cpns_if']; ?>
减<?php echo $this->_tpl_vars['list']['cpns_then']; ?>
</td>
                    <td><?php if ($this->_tpl_vars['list']['type'] == 2 || $this->_tpl_vars['list']['type'] == 4 || $this->_tpl_vars['list']['type'] == 5): ?>第<?php echo $this->_tpl_vars['list']['start_time']; ?>
天开始<br/>有效<?php echo $this->_tpl_vars['list']['end_time']; ?>
天<?php else: ?><?php echo ((is_array($_tmp=$this->_tpl_vars['list']['start_time'])) ? $this->_run_mod_handler('date_format', true, $_tmp, "%Y-%m-%d %H:%M") : smarty_modifier_date_format($_tmp, "%Y-%m-%d %H:%M")); ?>
 -<br/> <?php echo ((is_array($_tmp=$this->_tpl_vars['list']['end_time'])) ? $this->_run_mod_handler('date_format', true, $_tmp, "%Y-%m-%d %H:%M") : smarty_modifier_date_format($_tmp, "%Y-%m-%d %H:%M")); ?>
<?php endif; ?></td>
                    <td><a href="?m=activity&s=coupons.php&operation=users&cpns_id=<?php echo $this->_tpl_vars['list']['id']; ?>
"><?php echo $this->_tpl_vars['list']['cpns_nums']; ?>
</a></td>
                    <td><?php if ($this->_tpl_vars['list']['type'] == 1): ?><a href="?m=activity&s=coupons.php&operation=users&cpns_id=<?php echo $this->_tpl_vars['list']['id']; ?>
"><?php echo $this->_tpl_vars['list']['cpns_sends']; ?>
</a><?php endif; ?></td>
                    <td><?php if ($this->_tpl_vars['list']['type'] == 1): ?><a href="?m=activity&s=coupons.php&operation=users&cpns_id=<?php echo $this->_tpl_vars['list']['id']; ?>
"><?php echo $this->_tpl_vars['list']['cpns_binds']; ?>
</a><?php endif; ?></td>
                    <td><a href="?m=activity&s=coupons.php&operation=users&cpns_id=<?php echo $this->_tpl_vars['list']['id']; ?>
"><?php echo $this->_tpl_vars['list']['cpns_used']; ?>
</a></td>
                    <td>&nbsp;<?php echo ((is_array($_tmp=@$this->_tpl_vars['list']['catid'])) ? $this->_run_mod_handler('default', true, $_tmp, '全分类') : smarty_modifier_default($_tmp, '全分类')); ?>
</td>
                    <td><?php if ($this->_tpl_vars['list']['type'] == 1): ?>唯一编号<?php elseif ($this->_tpl_vars['list']['type'] == 2): ?>积分兑换<?php elseif ($this->_tpl_vars['list']['type'] == 3): ?>页面领取<?php elseif ($this->_tpl_vars['list']['type'] == 4): ?>事件触发<?php elseif ($this->_tpl_vars['list']['type'] == 5): ?>会员分享<?php else: ?>通用码<?php endif; ?></td>
                    <td><?php if ($this->_tpl_vars['list']['status'] == 1): ?>开启<?php else: ?>关闭<input type="hidden" value="<?php echo $this->_tpl_vars['list']['id']; ?>
" id="cpns_status_<?php echo $this->_tpl_vars['list']['id']; ?>
"/><?php endif; ?></td>
                    <td><input type="hidden" value="<?php echo $this->_tpl_vars['list']['id']; ?>
" id="cpns_id_<?php echo $this->_tpl_vars['list']['id']; ?>
"/>
                    <?php if ($this->_tpl_vars['list']['type'] == 0 || $this->_tpl_vars['list']['type'] == 1): ?>
                    <p style="color:#000;"><input type="radio" value="short" name="make_type_<?php echo $this->_tpl_vars['list']['id']; ?>
" <?php if ($this->_tpl_vars['list']['type'] == 0): ?>checked<?php endif; ?> id="ms_<?php echo $this->_tpl_vars['list']['id']; ?>
"/><label style="float:left" for="ms_<?php echo $this->_tpl_vars['list']['id']; ?>
">短码</label><input type="radio" name="make_type_<?php echo $this->_tpl_vars['list']['id']; ?>
" <?php if ($this->_tpl_vars['list']['type'] == 1): ?>checked<?php endif; ?> value="lang" id="ml_<?php echo $this->_tpl_vars['list']['id']; ?>
"/><label style="float:left" for="ml_<?php echo $this->_tpl_vars['list']['id']; ?>
">长码</label></p>
                    <p style="color:#000;"><input type="button" value="生成" nc_type="<?php echo $this->_tpl_vars['list']['id']; ?>
">
                    <input type="text" value="<?php if ($this->_tpl_vars['list']['type'] == 1): ?>10<?php else: ?>1<?php endif; ?>" class="w50" id="cpns_nums_<?php echo $this->_tpl_vars['list']['id']; ?>
"/>张</p>
                    
                    <?php endif; ?>
                    </td>
                    <td>
                    <a href="?m=activity&s=coupons.php&operation=edit&editid=<?php echo $this->_tpl_vars['list']['id']; ?>
"><?php echo $this->_tpl_vars['editimg']; ?>
</a> 
                    <a onclick="return confirm('确定删除吗，已生成的也全部删除哦！');" href="?m=activity&s=coupons.php&delid=<?php echo $this->_tpl_vars['list']['id']; ?>
"><?php echo $this->_tpl_vars['delimg']; ?>
</a> 
                    </td>
                </tr>
                <?php endforeach; else: ?>
                <tr>
                    <td class="norecord" colspan="99"><i></i><span>暂无符合条件的数据记录</span></td>
                </tr>
                <?php endif; unset($_from); ?>
            </tbody>
            <tfoot>
                <tr>
                	<td colspan="99">
                        <input type="checkbox" class="checkall" id="del">
                        <input type="hidden" name="act" value="op" />
                        <input type="submit" value="提交" />
                    	<div class="page"><?php echo $this->_tpl_vars['de']['page']; ?>
</div>
                    </td>
                </tr>
            </tfoot>
        </table>
        </form>
        <?php endif; ?>
    </div>
</body>
</html>